package com.example.flowermall.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.flowermall.entity.UserAddress;
import com.example.flowermall.mapper.UserAddressMapper;
import com.example.flowermall.service.IUserAddressService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xiaoman
 * @since 2023-09-04
 */
@Service
public class UserAddressServiceImpl extends ServiceImpl<UserAddressMapper, UserAddress> implements IUserAddressService {

    @Autowired
    UserAddressMapper userAddressMapper;
    @Override
    public List<UserAddress> getListByUserId(Integer id) {
        LambdaQueryWrapper<UserAddress> queryWrapper=new LambdaQueryWrapper<>();
        queryWrapper.eq(UserAddress::getUserId,id);
        List<UserAddress> list = userAddressMapper.selectList(queryWrapper);
        return list;
    }

    @Override
    public UserAddress getUserAddressById(Integer id) {
        UserAddress userAddress = userAddressMapper.selectById(id);
        return userAddress;
    }

    @Override
    public void updateUserAddress(UserAddress userAddress) {
        userAddressMapper.updateById(userAddress);
    }

    @Override
    public void deleteById(Integer id) {
        userAddressMapper.deleteById(id);
    }

    @Override
    public Integer countByUserId(Integer userId) {
        Integer count = userAddressMapper.selectCount(userId);
        return count;
    }
}
